<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>tinyOS: tBitmap.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">tinyOS
   &#160;<span id="projectnumber">v1.00</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('t_bitmap_8c_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">tBitmap.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="t_bitmap_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="t_lib_8h.html">tLib.h</a>&quot;</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div><div class="line"><a name="l00021"></a><span class="lineno"><a class="line" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#gabe65280030fc295bb9eecc4a8672544f">   21</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#gabe65280030fc295bb9eecc4a8672544f">tBitmapInit</a> (<a class="code" href="structt_bitmap.html">tBitmap</a> *bitmap) {</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;    bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> = 0;</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;}</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;</div><div class="line"><a name="l00029"></a><span class="lineno"><a class="line" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga24bbbd4e9273fa00e125cbf600c851c1">   29</a></span>&#160;uint32_t <a class="code" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga24bbbd4e9273fa00e125cbf600c851c1">tBitmapPosCount</a> (<span class="keywordtype">void</span>) {</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="keywordflow">return</span> 32;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;}</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga77e6ff906f4751ea7f055562b94cad54">   38</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga77e6ff906f4751ea7f055562b94cad54">tBitmapSet</a> (<a class="code" href="structt_bitmap.html">tBitmap</a> *bitmap, uint32_t pos) {</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> |= 1 &lt;&lt; pos;</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;}</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga63a37ae88a06249de873bb54340de517">   47</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga63a37ae88a06249de873bb54340de517">tBitmapClear</a> (<a class="code" href="structt_bitmap.html">tBitmap</a> *bitmap, uint32_t pos) {</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &amp;= ~(1 &lt;&lt; pos);</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;}</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"><a class="line" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#gae86fbb239ac4694acf71b11c7cc6b479">   56</a></span>&#160;uint32_t <a class="code" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#gae86fbb239ac4694acf71b11c7cc6b479">tBitmapGetFirstSet</a> (<a class="code" href="structt_bitmap.html">tBitmap</a> *bitmap) {</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;    <span class="comment">// 快速查找表，用于实现8位宽数据中第1个置1的位置序号</span></div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <span class="keyword">static</span> <span class="keyword">const</span> uint8_t quickFindTable[] = {</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;            <span class="comment">/* 00 */</span> 0xff, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;            <span class="comment">/* 10 */</span>    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;            <span class="comment">/* 20 */</span>    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;            <span class="comment">/* 30 */</span>    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;            <span class="comment">/* 40 */</span>    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;            <span class="comment">/* 50 */</span>    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;            <span class="comment">/* 60 */</span>    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;            <span class="comment">/* 70 */</span>    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;            <span class="comment">/* 80 */</span>    7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;            <span class="comment">/* 90 */</span>    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;            <span class="comment">/* A0 */</span>    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;            <span class="comment">/* B0 */</span>    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;            <span class="comment">/* C0 */</span>    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;            <span class="comment">/* D0 */</span>    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;            <span class="comment">/* E0 */</span>    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;            <span class="comment">/* F0 */</span>    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    };</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    <span class="comment">// 将32位依次折成多个8位，利用查找表进行快速查找</span></div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    <span class="keywordflow">if</span> (bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &amp; 0xff) {</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        <span class="keywordflow">return</span> quickFindTable[(bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &gt;&gt;  0) &amp; 0xff] + 0;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &amp; 0xff00) {</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;        <span class="keywordflow">return</span> quickFindTable[(bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &gt;&gt;  8) &amp; 0xff] + 8;</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &amp; 0xff0000) {</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;        <span class="keywordflow">return</span> quickFindTable[(bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &gt;&gt; 16) &amp; 0xff] + 16;</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &amp; 0xFF000000) {</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;        <span class="keywordflow">return</span> quickFindTable[(bitmap-&gt;<a class="code" href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">bitmap</a> &gt;&gt; 24) &amp; 0xFF] + 24;</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga24bbbd4e9273fa00e125cbf600c851c1">tBitmapPosCount</a>();</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    }</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;}</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;</div><div class="ttc" id="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84_html_ga63a37ae88a06249de873bb54340de517"><div class="ttname"><a href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga63a37ae88a06249de873bb54340de517">tBitmapClear</a></div><div class="ttdeci">void tBitmapClear(tBitmap *bitmap, uint32_t pos)</div><div class="ttdef"><b>Definition:</b> <a href="t_bitmap_8c_source.html#l00047">tBitmap.c:47</a></div></div>
<div class="ttc" id="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84_html_gae86fbb239ac4694acf71b11c7cc6b479"><div class="ttname"><a href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#gae86fbb239ac4694acf71b11c7cc6b479">tBitmapGetFirstSet</a></div><div class="ttdeci">uint32_t tBitmapGetFirstSet(tBitmap *bitmap)</div><div class="ttdef"><b>Definition:</b> <a href="t_bitmap_8c_source.html#l00056">tBitmap.c:56</a></div></div>
<div class="ttc" id="t_lib_8h_html"><div class="ttname"><a href="t_lib_8h.html">tLib.h</a></div></div>
<div class="ttc" id="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84_html_gabe65280030fc295bb9eecc4a8672544f"><div class="ttname"><a href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#gabe65280030fc295bb9eecc4a8672544f">tBitmapInit</a></div><div class="ttdeci">void tBitmapInit(tBitmap *bitmap)</div><div class="ttdef"><b>Definition:</b> <a href="t_bitmap_8c_source.html#l00021">tBitmap.c:21</a></div></div>
<div class="ttc" id="structt_bitmap_html_adc5b4308ed7b0d1a073896de1d25636a"><div class="ttname"><a href="structt_bitmap.html#adc5b4308ed7b0d1a073896de1d25636a">tBitmap::bitmap</a></div><div class="ttdeci">uint32_t bitmap</div><div class="ttdef"><b>Definition:</b> <a href="t_lib_8h_source.html#l00019">tLib.h:19</a></div></div>
<div class="ttc" id="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84_html_ga24bbbd4e9273fa00e125cbf600c851c1"><div class="ttname"><a href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga24bbbd4e9273fa00e125cbf600c851c1">tBitmapPosCount</a></div><div class="ttdeci">uint32_t tBitmapPosCount(void)</div><div class="ttdef"><b>Definition:</b> <a href="t_bitmap_8c_source.html#l00029">tBitmap.c:29</a></div></div>
<div class="ttc" id="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84_html_ga77e6ff906f4751ea7f055562b94cad54"><div class="ttname"><a href="group___xE4_xBD_x8D_xE5_x9B_xBE_xE7_xBB_x93_xE6_x9E_x84.html#ga77e6ff906f4751ea7f055562b94cad54">tBitmapSet</a></div><div class="ttdeci">void tBitmapSet(tBitmap *bitmap, uint32_t pos)</div><div class="ttdef"><b>Definition:</b> <a href="t_bitmap_8c_source.html#l00038">tBitmap.c:38</a></div></div>
<div class="ttc" id="structt_bitmap_html"><div class="ttname"><a href="structt_bitmap.html">tBitmap</a></div><div class="ttdef"><b>Definition:</b> <a href="t_lib_8h_source.html#l00018">tLib.h:18</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="t_bitmap_8c.html">tBitmap.c</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>
